package com.example.demo.mapper;

import com.example.demo.mapper.entity.Badge;
import com.example.demo.mapper.entity.StudentBadge;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-13 19:39
 */
@Mapper
@Repository
public interface StudentBadgeMapper {
    @Select("SELECT COUNT(*) FROM student_badge WHERE student_id = #{studentId}")
    int selectBadgeNumber(int studentId);
    @Select("SELECT * FROM badge WHERE type = #{type}")
    List<Badge> selectTypeBadge(int type);
    @Select("SELECT * FROM student_badge WHERE student_id = #{studentId}")
    List<StudentBadge> selectStudentBadgeById(int studentId);

    @Select("SELECT * FROM badge WHERE badge_id = #{badgeId}")
    Badge selectBadgeById(int badgeId);

    @Select("SELECT * FROM student_badge WHERE student_id = #{studentId} AND badge_id = #{badgeId}")
    StudentBadge selectStudentBadge(@Param("studentId") int studentId, @Param("badgeId") int badgeId);
    @Select("SELECT * FROM badge WHERE attribute_id = #{attributeId}")
    List<Badge> selectBadgeByAttributeId(int attributeId);
    @Select("SELECT * FROM badge WHERE attribute_id = #{attributeId} ORDER BY attribute_value LIMIT 1")
    Badge selectJuniorBadgeByAttributeId(int attributeId);
    @Insert("INSERT INTO student_badge(student_id, badge_id) " +
            "   VALUES(#{studentId}, #{badgeId})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insertStudentBadge(StudentBadge studentBadge);
}
